package com.geuso.xingdutch.numbers;

import android.app.ListFragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.geuso.xingdutch.R;
import com.geuso.xingdutch.activity.DefaultActivity;

public class NumbersActivity extends DefaultActivity {

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.main);
		getFragmentManager().beginTransaction().add(R.id.container, new NumbersOverviewFragment()).commit();
		
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    // Inflate the menu items for use in the action bar
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.numbers_overview_actions, menu);
	    return super.onCreateOptionsMenu(menu);
	}

	@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.action_exercise:
        	Intent intent = new Intent(this, NumbersExerciseActivity.class);
			this.startActivity(intent);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
	
	public static class NumbersOverviewFragment extends ListFragment {

		public NumbersOverviewFragment() {
		}

		@Override
		public void onActivityCreated(Bundle savedInstanceState){
			super.onActivityCreated(savedInstanceState);
			
			setListAdapter(new NumbersListAdapter(getActivity(), NumbersData.numbers));
		}
	}
	
}
